//
//  AIGirlBaseViewController.swift
//  AIGirl
//
//  Created by Rae on 2023/12/22.
//

import UIKit

@objc protocol AIGirlBaseViewControllerProtocol {
    func controller_identification() -> String
    func controller_backImage() -> UIImage?
}

extension UIViewController: AIGirlBaseViewControllerProtocol {
    
    func controller_identification() -> String {
        return NSStringFromClass(self.classForCoder)
    }
    
    func controller_backImage() -> UIImage? {
        UIImage(named: "")
    }
    
}

class AIGirlBaseViewController: UIViewController,AnimationProtocol {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        navigation.bar.isHidden = true
        view.backgroundColor = "#262C61".toColor
        NotificationCenter.default.addObserver(self,
                                               selector: #selector(screenCaptured),
                                               name: UIApplication.userDidTakeScreenshotNotification,
                                               object: nil)
        NotificationCenter.default.addObserver(self,
                                               selector: #selector(screenRecordingDetected),
                                               name: UIScreen.capturedDidChangeNotification,
                                               object: nil)
    }
    
    // 截屏通知的处理方法
    @objc func screenCaptured() {

        animation.animation(show: AIGirlBanView())
        
        DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
            self.animation.animation(dismiss: AIGirlBanView())
        }
    }
    
    @objc func screenRecordingDetected(){
        if UIScreen.main.isCaptured {
            // 用户开始录屏，你可以在此处执行相应的操作，例如暂停应用或显示提示
            animation.animation(show: AIGirlBanView())
            
        } else {
            // 录屏停止，你可以在此处执行相应的操作，例如恢复应用
            animation.animation(dismiss: AIGirlBanView())
        }
    }
    
    @objc func clickBackButton(){
        
        self.navigationController?.popViewController(animated: true)
    }
}
